package njupt.proxy;
import java.util.List;

import njupt.dao.OrderDAO;

import njupt.daoimp.OrderDAOimp;
import njupt.dbc.DatabaseConnnection;
import njupt.vo.Cart;


public class OrderDAOProxy implements OrderDAO {
	DatabaseConnnection dbc =null;
	private OrderDAO dao;
	public OrderDAOProxy(){
		try{	
		this.dbc=new DatabaseConnnection();
		}catch(Exception e){
			e.printStackTrace();
		}
		
		if(this.dbc.getConnection()==null){
			System.out.println("error collection!!");
		}
		this.dao=new OrderDAOimp(this.dbc.getConnection());
	}
	public int createorder(Cart cart, String userid) throws Exception{	
		int flag=0;
		System.out.println("flag"+flag);
		System.out.println("user"+userid);
		try{
			 flag=this.dao.createorder(cart,userid);	 
		}catch(Exception e){
			throw e;
		}
		return flag;
	}
	public List<String[]> selectorder(int userid) throws Exception {
		  try{
			  return this.dao.selectorder(userid);
		  }catch(Exception e){
			  throw e;
		  }finally{
			  this.dbc.close();
		  }
		
	}
	/* (non-Javadoc)
	 * @see njupt.dao.OrderDAO#createordermsg(njupt.vo.Cart, int)
	 */
	public int createorderdetail(Cart cart, int orderid) throws Exception {
		try{
			return this.dao.createorderdetail(cart, orderid);
		}catch(Exception e){
			throw e;
			     }finally{
				  this.dbc.close();
			  }
		
	}
	/* (non-Javadoc)
	 * @see njupt.dao.OrderDAO#selectorderdetail(int)
	 */
	public List<String[]> selectorderdetail(int orderid) throws Exception {
		try{
			return this.dao.selectorderdetail(orderid);
		}catch(Exception e){
			throw e;
			     }finally{
				  this.dbc.close();
			  }
	}
	/* Overriding methods
	 */
	public int updateBuyStatus(Cart cart, int orderid) throws Exception {
		try{
			return this.dao.updateBuyStatus(cart, orderid);
		}catch(Exception e){
			throw e;
			     }finally{
				  this.dbc.close();
			  }
	}
	

}
